package com.java.service;

import com.java.dao.IntoAndOutMapper;
import com.java.pojo.EnterGood;
import com.java.pojo.IntoAndOut;
import com.java.pojo.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 进出库
 */
@Service("interService")
public class IntoAndOutServiceImpl implements IntoAndOutService {
    @Autowired
    private IntoAndOutMapper intoAndOutMapper;

    @Override
    public int Add(IntoAndOut intoAndOut) {
        return intoAndOutMapper.Add(intoAndOut);
    }

    @Override
    public Integer getCount(String documentid) {
        return intoAndOutMapper.getCount(documentid,0);
    }

    /*出库前*/
    @Override
    public Page<IntoAndOut> getPageByPage(Integer a, String documentid) {
        int b=4;//显示条数
        Page<IntoAndOut> page=new Page<>();
        page.setCurryPage(a);//设置当前页码
        page.setRows(b);//设置每页显示的条数
        Integer count = intoAndOutMapper.getCount(documentid,0);//总条数
        page.setTotalCount(count);//总条数
        int start=(a-1)*b;/*开始的索引*/
        List<IntoAndOut> list = intoAndOutMapper.getListdocumentidByPage(start, b, documentid);
        page.setList(list);/*赋值list*/
        int totalPae=count % b==0 ? count / b : (count / b)+1;
        page.setTotalPae(totalPae);/*设置总页数*/
        if(page==null){
            page=null;
        }
        return page;
    }

    /*出库后*/
    @Override
    public Page<IntoAndOut> getPageByPage2(Integer a, String documentid) {
        int b=4;//显示条数
        Page<IntoAndOut> page=new Page<>();
        page.setCurryPage(a);//设置当前页码
        page.setRows(b);//设置每页显示的条数
        Integer count = intoAndOutMapper.getCount(documentid,1);//总条数
        page.setTotalCount(count);//总条数
        int start=(a-1)*b;/*开始的索引*/
        List<IntoAndOut> list = intoAndOutMapper.getListdocumentidByPage2(start, b, documentid);
        page.setList(list);/*赋值list*/
        int totalPae=count % b==0 ? count / b : (count / b)+1;
        page.setTotalPae(totalPae);/*设置总页数*/
        if(page==null){
            page=null;
        }
        return page;
    }

    @Override
    public Integer getCount(String documentid, Integer okandno) {
        return intoAndOutMapper.getCount(documentid,okandno);
    }

    @Override
    public int update2(Integer a) {
        return intoAndOutMapper.update2(a);
    }

    @Override
    public int updOutUPInt(String goodname) {
        return intoAndOutMapper.updOutUPInt(goodname);
    }
}
